package com.topstack.arouterstudy

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.topstack.arouterstudy.Demo2.Book
import com.topstack.arouterstudy.databinding.ActivityMainBinding

@Route(path = "/activity/main")
class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.toDemo1.setOnClickListener {
            ARouter.getInstance().build("/activity/demo1")
                .navigation()
        }
        binding.toDemo2.setOnClickListener {
            ARouter.getInstance().build("/activity/demo2")
                .withString("text", binding.input.text.toString())
                .withObject("book", Book(2, "第一行代码"))
                .navigation()
        }

        binding.toDemo3.setOnClickListener {
            val fragment: Fragment =
                ARouter.getInstance().build("/fragment/demo3").navigation() as Fragment
            supportFragmentManager.beginTransaction()
                .replace(R.id.fragment_container, fragment)
                .commitNow()
        }

        binding.toDemo4.setOnClickListener {
            ARouter.getInstance().build("/module/demo4")
                .navigation()
        }

    }

}